package cloud.xlh.my_system.tradeflow;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/1/8 13:16
 * @ Description:
 */
public class EcnyTradeFlowBuilder {

    private List<TradeProcess> processList = new ArrayList<>(16);

    private TradeErrHandler errHandler;

    public static EcnyTradeFlowBuilder get() {
        return new EcnyTradeFlowBuilder();
    }

    public EcnyTradeFlowBuilder checkMsg(CheckMsg checkMsg) {
        processList.add(checkMsg);
        return this;
    }

    public EcnyTradeFlowBuilder initTxn(InitTxn initTxn) {
        processList.add(initTxn);
        return this;
    }

    public EcnyTradeFlowBuilder saveTxn(SaveTxn saveTxn) {
        processList.add(saveTxn);
        return this;
    }

    public EcnyTradeFlowBuilder initRspMsg(Response response) {
        processList.add(response);
        return this;
    }

    /**
     * 采用默认的数据库保存服务
     *
     * @return
     */
    public EcnyTradeFlowBuilder saveTxn() {
//    	processList.add(RtpUtil.getInstance().getBean("ecnySaveTxn", SaveTxn.class));
        return this;
    }


    public EcnyTradeFlowBuilder process(TradeProcess process) {
        processList.add(process);
        return this;
    }

    public EcnyTradeFlowBuilder updateTxn(UpdateTxn updateTxn) {
        processList.add(updateTxn);
        return this;
    }

    /**
     * 采用默认的数据库更新
     *
     * @return
     */
    public EcnyTradeFlowBuilder updateTxn() {
//    	processList.add(RtpUtil.getInstance().getBean("ecnyUpdateTxn", UpdateTxn.class));
        return this;
    }

    public EcnyTradeFlowBuilder response(Response response) {
        processList.add(response);
        return this;
    }

    public EcnyTradeFlowBuilder errHandler(TradeErrHandler handler) {
        this.errHandler = handler;
        return this;
    }


    public TradeFlow build() {

        TradeFlow tradeFlow = new TradeFlow(processList);

        //添加异常处理器
        if (errHandler != null) {
            tradeFlow.setTradeErrHandler(errHandler);
        }

        return tradeFlow;
    }
}

